﻿//检查是否有操作过 0未操作 1:加减分操作
var isOP=0;
//点击回答问题事件
function AnswerQuestion()
{
    if(!CheckLogin()) return;
    if($("answerQ").style.display=="none")
    {
        $("answerQ").style.display="";        
    }
	$("aTextarea").focus();
	$scroller$("subButton",100);    
}
//回答问题
function AddAnswer()
{
    if(!CheckLogin()) return;    
    if($("aTextarea").value.length<2||$("aTextarea").value.length>2000)
    {
        $("errorAnswer").style.display="";
        return;
    }
    if(isOP!=0)
    {
        return;
    }    
    $("errorAnswer").style.display="none";
    $("subButton").disabled = true;
    WebServices.WWW.Answers.AddQAnswer(CurQID,$("aTextarea").value,onsuccOP);
}
function onsuccOP(result)
{   
    if(result.State)
    {
        TopLocat();
    }
    else
    {
        if($("subButton")!=null)
        {
            $("subButton").disabled = false;
        }
    }
    showProgressBar(false,true);  
}
//替换分数
function onsuccPoint(result,aid)
{
    if(result.State)
    {        
        $("Point"+aid).innerHTML=$("PointItem").innerHTML.replace(/\$Points\$/gi,result.Effect)
        isOP=0;
    }
}
//打分
function AnswerMark(mark,aid)
{
    if(!CheckLogin()) return;
    if(isOP==1)
    {
        return;
    }
    isOP=1;
    if(mark)
    {
        $("add"+aid).style.display="none";
        $("sub"+aid).style.display="";
        $("1add"+aid).style.display="";
        $("1sub"+aid).style.display="none";
    }
    else
    {
        $("add"+aid).style.display="";
        $("sub"+aid).style.display="none";
        $("1add"+aid).style.display="none";
        $("1sub"+aid).style.display="";
    }    
    WebServices.WWW.Answers.AnswerMark(aid,mark,onsuccPoint,null,aid);
}
//操作转向页面
function TopLocat()
{
    var orderType=1;
    if($("selOrder")!=null)
    {
        orderType=$("selOrder").value;
    }
    top.location = "/answers/question/"+CurQID+"-"+CurPageIndex+"-"+orderType+"-2.htm";    
}
//检查是否登录
function CheckLogin()
{
   if(!Memberno||Memberno=="")
    {
        var orderType=1;
        if($("selOrder")!=null)
        {
            orderType=$("selOrder").value;
        }
        top.location = "/user/login.htm?IsShow=1&ReturnUrl="+WWWHost+"/answers/question/"+CurQID+"-"+CurPageIndex+"-"+orderType+"-2.htm";        
        return false;        
    }
    return true; 
}
//共享资源
function openDiv1(url,title,clstxt,width,height)
{
    if(!Memberno||Memberno=="")
    {
        top.location = "/user/login.htm?IsShow=1&ReturnUrl="+top.location.href;
        return;
    }
    openDiv(url,title,clstxt,width,height);
}
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();